<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="产品名称" prop="goodsName">
                <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <!--<el-form-item label="产品型号明细" prop="goodsBrand">
                <el-input v-model="queryParams.goodsBrand" placeholder="请输入产品型号明细"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>-->
            <el-form-item label="产品型号" prop="goodModel">
                <el-input v-model="queryParams.goodModel" placeholder="请输入产品型号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="需求日期" prop="saleDate">
                <el-date-picker clearable v-model="queryParams.saleDate"
                                type="date" value-format="yyyy-MM-dd" placeholder="请选择需求日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="客户名称" prop="customerName">
                <el-input v-model="queryParams.customerName" placeholder="请输入客户名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="订单编号" prop="projectId">
                <el-input v-model="queryParams.projectId" placeholder="请输入订单编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="订单名称" prop="projectName">
                <el-input v-model="queryParams.projectName" placeholder="请输入订单名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <!--<el-form-item label="回款时间" prop="huikuanDate">
                <el-date-picker clearable v-model="queryParams.huikuanDate"
                                type="date" value-format="yyyy-MM-dd" placeholder="请选择回款时间">
                </el-date-picker>
            </el-form-item>-->
            <el-form-item label="产品编码" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入产品编码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <!--<el-form-item label="单据号" prop="nos">
                <el-input v-model="queryParams.nos" placeholder="请输入单据号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>-->
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

       <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:GoodsSaledo:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:GoodsSaledo:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:GoodsSaledo:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:GoodsSaledo:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>-->

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="单据号" align="center" prop="nos"/>
            <el-table-column label="订单编号" align="center" prop="projectId"/>
            <el-table-column label="订单数量" align="center" prop="counts"/>
            <el-table-column label="自制数量" align="center" prop="shengyu"/>
            <el-table-column label="产品编码" align="center" prop="code"/>
            <el-table-column label="产品名称" align="center" prop="goodsName"/>
           <!-- <el-table-column label="产品型号明细" align="center" prop="goodsBrand"/>-->
            <el-table-column label="产品型号" align="center" prop="goodModel"/>
            <!--<el-table-column label="销售单价" align="center" prop="goodsUnitPrice"/>
            <el-table-column label="销售数量" align="center" prop="goodsCount"/>
            <el-table-column label="总价" align="center" prop="goodsTotalPrice"/>
            <el-table-column label="成本单价" align="center" prop="goodsBuyPrice"/>
            <el-table-column label="成本金额" align="center" prop="goodsBuyTotal"/>-->
            <el-table-column label="客户名称" align="center" prop="customerName"/>
            <el-table-column label="销售人姓名" align="center" prop="saleName"/>
            <el-table-column label="状态" align="center" prop="status"/>
            <!--<el-table-column label="是否发货" align="center" prop="isfahuo"/>
            <el-table-column label="发货时间" align="center" prop="fahuoDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.fahuoDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="回款时间" align="center" prop="huikuanDate" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.huikuanDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
            </el-table-column>-->
            <el-table-column label="备注" align="center" prop="remark"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleGongxu(scope.row)">工艺工序</el-button>
                  <el-button size="mini" type="text" icon="el-icon-edit"
                             @click="handleTask(scope.row)">生产任务</el-button>
                  <el-button size="mini" type="text" icon="el-icon-edit"
                             @click="handleBaogong(scope.row)">生产报工</el-button>
                  <el-button size="mini" type="text" icon="el-icon-edit"
                             @click="handleJindu(scope.row)">生产进度</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit"
                               @click="handleXunjian(scope.row)">巡检</el-button>
                  <!--<el-button size="mini" type="text" icon="el-icon-edit"
                             @click="handleUpdate(scope.row)">同步订单</el-button>-->
                    <!--<el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:GoodsSaledo:remove']">删除</el-button>
                    </el-popconfirm>-->
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <goodsSaledo-form ref="form" @ok="getList"></goodsSaledo-form>
        <goodsGongxu-form ref="gongxuForm" @ok="getList"></goodsGongxu-form>
        <goodsTask-form ref="taskForm" @ok="getList"></goodsTask-form>
        <goodsBaogong-form ref="baogongForm" @ok="getList"></goodsBaogong-form>
        <goodsJindu-form ref="jinduForm" @ok="getList"></goodsJindu-form>
        <goodsXunjian-form ref="xunjianForm" @ok="getList"></goodsXunjian-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import GoodsSaledoForm from '@/views/develop/goodsSaledo/module/GoodsSaledoForm'
    import GoodsGongxuForm from '@/views/develop/goodsSaledo/module/GoodsGongxuForm'
    import GoodsTaskForm from '@/views/develop/goodsSaledo/module/GoodsTaskForm'
    import GoodsBaogongForm from '@/views/develop/goodsSaledo/module/GoodsBaogongForm'
    import GoodsJinduForm from '@/views/develop/goodsSaledo/module/GoodsJinduForm'
    import GoodsXunjianForm from '@/views/develop/goodsSaledo/module/GoodsXunjianForm'

    export default {
        name: "GoodsSaledoList",
        components: {
            GoodsSaledoForm,
            GoodsGongxuForm,
            GoodsTaskForm,
            GoodsBaogongForm,
            GoodsJinduForm,
            GoodsXunjianForm
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 请购单（自制/采购/外协）表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    type: null,
                    goodsId: null,
                    goodsName: null,
                    goodsBrand: null,
                    goodModel: null,
                    goodsUnitPrice: null,
                    goodsCount: null,
                    goodsTotalPrice: null,
                    goodsBuyPrice: null,
                    goodsBuyTotal: null,
                    goodsProfit: null,
                    saleDate: null,
                    supplierId: null,
                    supplierName: null,
                    customerId: null,
                    customerName: null,
                    invoice: null,
                    invoiceId: null,
                    invoiceNo: null,
                    fundCallback: null,
                    receipt: null,
                    saleId: null,
                    saleName: null,
                    projectId: null,
                    projectName: null,
                    status: null,
                    deptId: null,
                    deptName: null,
                    counts: null,
                    shengyu: null,
                    isfahuo: null,
                    fahuoDate: null,
                    huikuanDate: null,
                    code: null,
                    dun: null,
                    nos: null,
                    isdo: null,
                    mainId: null
                },
                url: {
                    list:'/goodsSaledo/goodsSaledo/list',
                    remove:'/goodsSaledo/goodsSaledo/',
                    export:'/goodsSaledo/goodsSaledo/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询请购单（自制/采购/外协）列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },

              handleGongxu(row) {
                this.$refs.gongxuForm.gongxuShow(row);
              },
              handleTask(row) {
                this.$refs.taskForm.taskShow(row);
              },
              handleBaogong(row) {
                this.$refs.baogongForm.baogongShow(row);
              },
              handleJindu(row) {
                this.$refs.jinduForm.jinduShow(row);
              },
              handleXunjian(row) {
                this.$refs.xunjianForm.xunjianUpdate(row);
              },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `goodsSaledo_${new Date().getTime()}.xlsx`)
            },
  }
};
</script>
